#include <tsin/display/GLImage.hpp>

#include <IL/il.h>
#define ILUT_USE_OPENGL
#include <IL/ilut.h>

using namespace tsin;

GLImage::GLImage()
        : width(0), height(0), textureName(0)
{
}

GLImage::~GLImage()
{
        if (textureName > 0)
                glDeleteTextures(1, &textureName);
}

bool GLImage::open(const char *path, StandardResolution res)
{
        textureName = ilutGLLoadImage((char*)path);
        if (textureName) {
                width = ilGetInteger(IL_IMAGE_WIDTH);
                height = ilGetInteger(IL_IMAGE_HEIGHT);
                resolution = res;
                return true;
        }
        return false;
}

int GLImage::getWidth()
{
        return width;
}

int GLImage::getHeight()
{
        return height;
}

GLuint GLImage::getHandle()
{
        return textureName;
}

StandardResolution GLImage::getResolution()
{
        return resolution;
}